package com.liuweiheng.cloud.thread;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

public class ThreadUtil<V> {

    private static ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-call-runner-%d").build();
    /**
     * 核心线程数、最大线程数、存活时间，时间单位，存放提交但未执行任务的队列，创建线程的工厂类，等待队列满后的策略
     */
    private static ExecutorService taskExe = new ThreadPoolExecutor(10,20,200L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),namedThreadFactory);

    public static<V> Future<V> submit(Callable<V> task) {
        return taskExe.submit(task);
    }

    public static void shutdown() {
        System.out.println("线程池关闭");
        taskExe.shutdown();

    }

}
